package com.itheima.app.manager;

import com.itheima.domain.mongo.Video;
import com.itheima.domain.mongo.VideoScore;
import com.itheima.service.mongo.VideoService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.bson.types.ObjectId;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//向mq发送消息
@Component
public class VideoMQManager {
    //针对视频的操作
    public static final Integer MOVEMENT_PUBLISH = 1;// 发视频
    public static final Integer MOVEMENT_LIKE = 2;// 点赞视频
    public static final Integer MOVEMENT_LOVE = 3;// 关注视频
    public static final Integer MOVEMENT_COMMENT = 4;// 评论视频
    public static final Integer MOVEMENT_DISLIKE = 5;// 取消点赞视频
    public static final Integer MOVEMENT_DISLOVE = 6;// 取消关注视频

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @DubboReference
    private VideoService videoService;

    public void sendMovement(Long userId, ObjectId videoId, Integer type) {
        VideoScore videoScore = new VideoScore();
        videoScore.setUserId(userId);
        //根据视频id查询视频vid
        Video video = videoService.findById(videoId);
        videoScore.setVideoId(video.getVid());//视频vid

        switch (type) {
            case 1: {
                videoScore.setScore(20d);
                break;
            }
            case 2: {
                videoScore.setScore(5d);
                break;
            }
            case 3: {
                videoScore.setScore(8d);
                break;
            }
            case 4: {
                videoScore.setScore(10d);
                break;
            }
            case 5: {
                videoScore.setScore(-5d);
                break;
            }
            case 6: {
                videoScore.setScore(-8d);
                break;
            }
        }

        // 发送mq消息
        rabbitTemplate.convertAndSend("tanhua.recommend.video", videoScore);
    }
}
